// pages/assetPage/assetPage.js
var wallet = require('../wallet.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
      iconNum:{},
      textData:'',
      assetLang:{},
      iconType:'BTC',
      tid:'1'
  },
  getMoneyCode:function(e){
    wx.navigateTo({
      url: './getMoneyCode/getMoneyCode',
    })
  },
  goAddCoin(){
    wx.navigateTo({
      url: './addCoin/addCoin',
    })
  },
 
  goTransfer:function(e){
    var id = e.currentTarget.id
    var coinType = {
      type: this.data.iconNum.list[id].coin_symbol,
      money: this.data.iconNum.list[id].money,
      balance: this.data.iconNum.list[id].balance,
      addre: this.data.iconNum.list[id].addr,
      ram_token_addr: this.data.iconNum.list[id].ram_token_addr,
      ram_status: this.data.iconNum.list[id].ram_status
    }
    //console.log(coinType)
    let chooseKey = wx.getStorageSync('chooseKey');
    if(chooseKey !=1){
      wx.removeStorageSync('userMessage')
    }
    // wx.removeStorageSync('chooseKey')
    wx.navigateTo({
      url: './transferRecord/transferRecord?coinType='+JSON.stringify(coinType) ,
      success:function(){
        wx.setStorage({
          key: "coinType",
          data:coinType
        })
      }

    })
  },
  getCoinType(){
    var $this = this
    var token = wx.getStorageSync('createUser').access_token; 
    wallet.post('home/main', {access_token: token}, function (res) {
        console.log(res)
        wx.hideNavigationBarLoading()
      /* console.log(res.data.list)
       let data = res.data.list.filter((req,index)=>{
       let q =  req.balance.replace(/^(\d+\.\d{4})\d+$/,'$1',function(q,index){})
       console.log(q)
         return req.balance
       })*/
      // console.log(data)          
        $this.setData({
          iconNum: res.data
        })
       
    })
  
  },
  goend(e){
  // console.log(this.x)
  // console.log(this.y)
  // console.log(e)
   let x = e.changedTouches[0].clientX;
   let y = e.changedTouches[0].clientY;
   let bottom = y -this.y
   let left = x -this.x
   if (bottom > 0 && Math.abs(left)<=80){
      var res = wx.getSystemInfoSync()//判断机型
      //console.log(res)
      if (/Android/i.test(res.system)) {
        //console.log('下滑')
        //console.log('333')
        //this.getCoinType && this.getCoinType()
        wx.startPullDownRefresh({
          success: function(res) {
            console.log(res)
          },
          fail: function(res) {},
          complete: function(res) {},
        })
      }
    }
  },
  gostart(e){
    //console.log(e)
   this.x = e.changedTouches[0].clientX;
    
   this.y = e.changedTouches[0].clientY;
   
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.x = 0;
    this.y = 0;
    var address = wx.getStorageSync('addressETH')
      //console.log(address)
      let dataText =address.substring(0, 10) + '...' + address.slice(-10)
      this.setData({
        textData:dataText
      })
      this.getCoinType && this.getCoinType()

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
   
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      assetLang: wx.T.locale == "zh-Hans" ? wx.T.locales['zh-Hans'] : wx.T.locales['en']

    })
    wx.setNavigationBarTitle({
      title: wx.T.locale == "zh-Hans" ? wx.T.locales['zh-Hans'].JLTabBarPropertyText : wx.T.locales['en'].JLTabBarPropertyText
    })
  wx.setTabBarItem({
      index: 0,
      text: wx.T.locale == "zh-Hans" ? wx.T.locales['zh-Hans'].JLTabBarPropertyText : wx.T.locales['en'].JLTabBarPropertyText,
      iconPath: "image/tab_zichan_normal.png",
      selectedIconPath: "image/tab_zichan_selected.png"
    })
    wx.setTabBarItem({
      index: 1,
      text: wx.T.locale == "zh-Hans" ? wx.T.locales['zh-Hans'].JLTabBarMineText : wx.T.locales['en'].JLTabBarMineText,
      iconPath: "image/tab_my_normal.png",
      selectedIconPath: "image/tab_my_selected.png"
    })
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    this.timer &&  clearTimeout(this.timer)
    this.timer3 && clearTimeout(this.timer3)
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.stopPullDownRefresh();  
    wx.showNavigationBarLoading()
    //console.log('下拉刷新')
    this.getCoinType && this.getCoinType()
   /* var res = wx.getSystemInfoSync()//判断机型
    if (/iOS/i.test(res.system)) {
      
    }*/
  },
  bindDownLoad(){
  /*var res = wx.getSystemInfoSync()//判断机型
  if (/Android/i.test(res.system)) {
    requestTask.abort()
  }*/
  },
  topLoad(){
  
  },
  scroll(){
    //console.log('滚动')
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    console.log(22)
  },
  onPageScroll(){
   
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})